import {createSlice} from "@reduxjs/toolkit"
import axios from "axios"
let hitokotoSlice = createSlice({
    name:"hitokoto",
    initialState:{
        value:null
    },
    reducers:{
        changehitokoto:(state,action)=>{
            state.value = action.payload

        }
    }
})

let {changehitokoto} = hitokotoSlice.actions
// 获取一句话数据
  export let getHitokoto = ()=>{
    return async (dispatch)=>{
        let {data:{hitokoto}} = await axios({
            method:"get",
            url:"https://v1.hitokoto.cn/?c=a"
        })
      
        dispatch(changehitokoto(hitokoto))

    }
}

export default hitokotoSlice.reducer